-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.x] Eager loading MorphTo relationship does not honor each models $keyType #34531
Conversation
Is this fixing this issue or a separate issue: #34331 |
This is fixing an issue I have with MySQL ignoring index usage when bound parameters are passed as ints when they are numeric due to PHP array behavior of not letting strings that are valid ints be array keys as strings. I do not have access to SQL Server but after reading his issue I believe this would solve it as well. He is welcome to test this on his code base first as it is a simple change. I'm sorry I did not open an issue first. Would you like me to or we can use that issue as it's the same answer I believe. |
Breaking change in minor release laravel/framework#34531
Breaking change in minor release laravel/framework#34531
Breaking change in minor release laravel/framework#34531
Breaking change in minor release laravel/framework#34531
Breaking change in minor release laravel/framework#34531
Breaking change in minor release laravel/framework#34531
Breaking change in minor release laravel/framework#34531
When eager loading a morphTo relationship that could contain models using a $keyType of 'string' each query that is built is not making sure the bound parameter is cast to string due to the dictionary being built using each model's ID as an array key.
Table A has morphTo "owner" relationship.
Table B is a related model that has a $keyType of string. Even though some of its values can be "numeric" at times.
Entries in table A for B include id values of [1,2,3]
When building the whereIn query for the database if you are not casting to a string MySQL will not use the index for that query when the column type is a char requiring a full table scan of Table B.
I really want to write tests for this but am not smart enough figure out a refactor that would give me the raw query before it's executed in
getResultsByType($type)
or even mock the query builder to catch the whereIn() call and examine the parameters passed in.Thanks for your consideration.